package com.woniuxy.threeproject.end_water_project_user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.threeproject.end_water_project_user.commons.Result;
import com.woniuxy.threeproject.end_water_project_user.domain.DetailsClassify;
import com.woniuxy.threeproject.end_water_project_user.dao.DetailsClassifyMapper;
import com.woniuxy.threeproject.end_water_project_user.exception.EndWaterRuntimeException;
import com.woniuxy.threeproject.end_water_project_user.service.IDetailsClassifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 文章分类表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@Service
@Slf4j
public class DetailsClassifyServiceImpl extends ServiceImpl<DetailsClassifyMapper, DetailsClassify> implements IDetailsClassifyService {

    @Resource
    private DetailsClassifyMapper detailsClassifyMapper;

    //根据id获取对应层次的分类
    @Override
    public Result findClassifyById(Integer id) {
        log.info("开始执行查询分类 {}",id);
        QueryWrapper<DetailsClassify> qw = new QueryWrapper<>();
        qw.eq("classify_id",id)
                .or()
                .eq("cid",id);
        List<DetailsClassify> detailsClassifies = detailsClassifyMapper.selectList(qw);
        if (detailsClassifies.size() ==0) {
            throw new  EndWaterRuntimeException("未查询到数据");
        }
        return Result.success("2002","查询成功",detailsClassifies);
    }
}
